package main

import (
	"fmt"
	"math/rand"
	"strconv"
	"strings"
	"time"
)

func work01() map[int]int {
	a := make([]int, 0, 10)
	res := make(map[int]int)
	var num int
	for i := 0; i < 100; i++ {
		rand.Seed(time.Now().UnixMicro())
		num = rand.Intn(128)
		a = append(a, num)
	}
	for i := 0; i < len(a); i++ {
		if v, exit := res[a[i]]; exit {
			res[i] = v + 1
		} else {
			res[i] = 1
		}
	}
	return res
}
func arr2string(data []int) string {
	var s = strings.Builder{}
	l := len(data)
	if l > 1 {
		for _, v := range data[:l-1] {
			s.WriteString(strconv.Itoa(v))
			s.WriteString(" ")
		}
		s.WriteString(strconv.Itoa(data[l-1]))
	} else if l==1 {
		s.WriteString(strconv.Itoa(data[0]))
	} 

	return s.String()
}

func main() {
	w1 := work01()
	fmt.Printf("作业一的结果为：%v\n", w1)
	data1 := []int{1}
	data2 := []int{1, 2, 3, 4, 5}
	w21 := arr2string(data1)
	w22 := arr2string(data2)
	w23:=arr2string([]int{})
	fmt.Printf("作业二的结果为：%#v\n", w21)
	fmt.Printf("作业二的结果为：%#v\n", w22)
	fmt.Printf("作业二的结果为：%#v\n", w23)
}
